package com.usian.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.behavior.ApLikesBehaviorApi;
import com.usian.behavior.service.ApLikesBehaviorService;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import com.usian.model.behavior.pojos.ApLikesBehavior;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/likes_behavior")
public class ApLikesBehaviorController implements ApLikesBehaviorApi {

    @Autowired
    ApLikesBehaviorService apLikesBehaviorService;

    /**
     *记录用户点赞、取消点赞行为
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @Override
    public ResponseResult like(@RequestBody LikesBehaviorDto dto) {
        return apLikesBehaviorService.like(dto);
    }


    /**
     * 远程调用 查询用户点赞行为  接口
     * @param entryId
     * @param articleId
     * @return
     */
    @GetMapping("/findLike/{entryId}/{articleId}")
    @Override
    public ApLikesBehavior findLike(@PathVariable Integer entryId,
                                    @PathVariable Long articleId) {
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery()
                .eq(ApLikesBehavior::getEntryId, entryId)
                .eq(ApLikesBehavior::getArticleId, articleId));

        return apLikesBehavior;
    }
}
